package com.ding.oauth.server.controller.thymeleaf;

import com.ding.oauth.server.entity.OauthClientDetails;
import com.ding.oauth.server.entity.User;
import com.ding.oauth.server.service.OauthClientDetailsService;
import com.ding.oauth.server.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * @author ding
 * @date 2021/3/24 11:43
 */

@Controller
public class IndexController {

    @Autowired
    private UserService userService;

    @Autowired
    private OauthClientDetailsService oauthClientDetailsService;
    @RequestMapping
    public String index() {
        return "index";
    }

    @RequestMapping("login")
    public String login() {
        return "login";
    }

    @GetMapping("userList")
    public String user(Model model){
        List<User> list = userService.list();
        model.addAttribute("userList", list);
        return "user";
    }


    @GetMapping("clientList")
    public String client(Model model){
        List<OauthClientDetails> list = oauthClientDetailsService.list();
        model.addAttribute("clientList", list);
        return "oauth-client";
    }


}
